package donjuan;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
//此面板用于添加数据，在注册新表以及添加数据时会出现，主要用途就是读取数据并调用Readin中方法来添加数据
public class Window_Login extends Panel_For_Login implements ActionListener {
  JTextField[] cin = new JTextField[5];
  
  JSplitPane[] frame = new JSplitPane[6];
  
  JSplitPane[] frame2 = new JSplitPane[5];
  
  JLabel[] hint = new JLabel[5];
  
  JButton conti;
  
  public static JButton skip;
  
  String[] data = new String[5];
  
  Window_Login() {
    for (int i = 0; i < 5; ) {
      this.data[i] = "";
      i++;
    } 
    setVisible(true);
    setBounds(50, 50, 300, 300);
    setName("请输入信息");
    setLayout(new FlowLayout());
    init();
  }
  void init() {
    this.conti = new JButton("添加");
    skip = new JButton("结束");
    skip.addActionListener(this);
    this.conti.addActionListener(this);
    int i;
    for (i = 0; i < 5; i++) {
      this.cin[i] = new JTextField(20);
      this.cin[i].setPreferredSize(new Dimension(20, 40));
    } 
    byte b;
    int j;
    JTextField[] arrayOfJTextField;
    for (j = (arrayOfJTextField = this.cin).length, b = 0; b < j; ) {
      JTextField temp = arrayOfJTextField[b];
      temp.addActionListener(this);
      b++;
    } 
    this.hint[0] = new JLabel("Account");
    this.hint[1] = new JLabel("Password");
    this.hint[2] = new JLabel("Website");
    this.hint[3] = new JLabel("Information");
    this.hint[4] = new JLabel("Note");
    for (i = 0; i < 5; i++)
      this.frame[i] = new JSplitPane(1, this.hint[i], this.cin[i]); 
    this.frame[5] = new JSplitPane(1, this.conti, skip);
    this.frame2[0] = new JSplitPane(0, this.frame[0], this.frame[1]);
    this.frame2[1] = new JSplitPane(0, this.frame2[0], this.frame[2]);
    this.frame2[2] = new JSplitPane(0, this.frame2[1], this.frame[3]);
    this.frame2[3] = new JSplitPane(0, this.frame2[2], this.frame[4]);
    this.frame2[4] = new JSplitPane(0, this.frame2[3], this.frame[5]);
    JButton muda = new JButton();
    muda.setVisible(false);
    muda.setBorder(BorderFactory.createRaisedBevelBorder());
    muda.setFont(new Font("华文行楷",1,15));
    JSplitPane end = new JSplitPane(0, muda, this.frame2[4]);
    add(end);
    skip.setBorder(BorderFactory.createRaisedBevelBorder());
    skip.setFont(new Font("华文行楷",1,15));
    conti.setBorder(BorderFactory.createRaisedBevelBorder());
    conti.setFont(new Font("华文行楷",1,15));
  }
  
  public static void change_mode() {
    skip.setName("返回");
  }
  
  public void actionPerformed(ActionEvent e) 
  {
    int i;
    if (this.conti == e.getSource()) 
    {
      byte b;
      int j;
      for (i = 0; i < 5; i++) 
      { this.data[i] = this.cin[i].getText();}
    
      if(data[4]==null||data[4].equals(""))
      {
    	  int p=Readin.count;
    	  data[4]=p+"";
      }
      JTextField[] arrayOfJTextField;
      for (j = (arrayOfJTextField = this.cin).length, b = 0; b < j; ) {
        JTextField temp = arrayOfJTextField[b];
        temp.setText("");
        b++;
      }
      Readin.add_data(Message.read, this.data, Message.state);
      for (i = 0; i < 5; ) {
        this.data[i] = "";
        i++;
      } 
    } else if (skip == e.getSource()) {
      Window_main.mode = 6;
      Window_main.jump();
    } 
  }
}
class Panel_For_Login extends JPanel{
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        ImageIcon bg=new ImageIcon("src/login.jpg");
        bg.paintIcon(this, g, 0, 0);
    }
}
